2000W / 48V LLC Battery-Charger  V1.00
startup_XMC1400.S
Go to the documentation of this file.
1 /*********************************************************************************************************************
2  * @file startup_XMC1400.S
3  * @brief CMSIS Core Device Startup File for Infineon XMC1400 Device Series
4  * @version V1.2
5  * @date 15 Sep 2017
6  *
7  * @cond
8  *********************************************************************************************************************
9  * Copyright (c) 2015-2017, Infineon Technologies AG
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
13  * following conditions are met:
14  *
15  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
16  * disclaimer.
17  *
18  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided with the distribution.
20  *
21  * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
33  * Infineon Technologies AG dave@infineon.com).
34  *********************************************************************************************************************
35  *
36  **************************** Change history ********************************
37  * V1.0, Sep, 03, 2015 JFT:Initial version
38  * MCLK=8MHz, PCLK=16MHz
39  * V1.1, Jan, 05, 2016 JFT:Fix .reset section attributes
40  * V1.2, Sep, 15, 2017 JFT:Added option to select wait time before ASC BSL channel selection (WAIT_ASCBSL_ENTRY_SSW)
41  *
42  * @endcond
43  */
44 
45 /*****************************************************************************
46  * <h> Clock system handling by SSW
47  * <h> CLK_VAL1 Configuration
48  * <o0.0..9> FDIV Fractional Divider Selection <0-1023>
49  * <i> Deafult: 0. Fractional part of clock divider, MCLK = DCO1 / (IDIV + (FDIV / 1024))
50  * <o0.10..17> IDIV Divider Selection <1-16>
51  * <i> Deafult: 6. Interger part of clock divider, MCLK = DCO1 / (IDIV + (FDIV / 1024) = 8MHz)
52  * <o0.18> PCLKSEL PCLK Clock Select
53  * <0=> PCLK = MCLK
54  * <1=> PCLK = 2 x MCLK
55  * <i> Deafult: 2 x MCLK
56  * <o0.19..21> RTCCLKSEL RTC Clock Select
57  * <0=> 32.768kHz standby clock
58  * <1=> 32.768kHz external clock from ERU0.IOUT0
59  * <2=> 32.768kHz external clock from ACMP0.OUT
60  * <3=> 32.768kHz external clock from ACMP1.OUT
61  * <4=> 32.768kHz external clock from ACMP2.OUT
62  * <5=> 32.768kHz XTAL clock via OSC_LP
63  * <6=> Reserved
64  * <7=> Reserved
65  * <i> Deafult: 32.768kHz standby clock
66  * <o0.31> do not move CLK_VAL1 to SCU_CLKCR[0..19]
67  * </h>
68  *****************************************************************************/
69 #define CLKVAL1_SSW 0x00041800
70 
71 /*****************************************************************************
72  * <h> CLK_VAL2 Configuration
73  * <o0.0> disable VADC and SHS Gating
74  * <o0.1> disable CCU80 Gating
75  * <o0.2> disable CCU40 Gating
76  * <o0.3> disable USIC0 Gating
77  * <o0.4> disable BCCU0 Gating
78  * <o0.5> disable LEDTS0 Gating
79  * <o0.6> disable LEDTS1 Gating
80  * <o0.7> disable POSIF0 Gating
81  * <o0.8> disable MATH Gating
82  * <o0.9> disable WDT Gating
83  * <o0.10> disable RTC Gating
84  * <o0.16> disable CCU81 Gating
85  * <o0.17> disable CCU41 Gating
86  * <o0.18> disable USIC1 Gating
87  * <o0.19> disable LEDTS2 Gating
88  * <o0.20> disable POSIF1 Gating
89  * <o0.21> disable MCAN0 Gating
90  * <o0.31> do not move CLK_VAL2 to SCU_CGATCLR0[0..10]
91  * </h>
92  *****************************************************************************/
93 #define CLKVAL2_SSW 0x00000100
94 
95 /*****************************************************************************
96  * <h> WAIT_ASCBSL_ENTRY Configuration
97  * <o0.0..30> Wait time before ASC BSL channel selection (number of MCLK clock cycles)
98  * <o0.31> Disable wait time before ASC BSL channel selection
99  * </h>
100  *****************************************************************************/
101 #define WAIT_ASCBSL_ENTRY_SSW 0x80000000
102 
103 /* A couple of macros to ease definition of the various handlers */
104 .macro Insert_InterruptHandler Interrupt
105  .weak \Interrupt\()_Handler
106  .thumb_set \Interrupt\()_Handler, Default_Handler
107 .endm
108 
109 .macro Insert_InterruptVeener Interrupt
110  .globl \Interrupt\()_Veener
111 \Interrupt\()_Veener:
112  LDR R0, =\Interrupt\()_Handler
113  BX R0
114 .endm
115 
116 /* ================== START OF VECTOR TABLE DEFINITION ====================== */
117 /* Vector Table - This is indirectly branched to through the veneers */
118  .syntax unified
119  .cpu cortex-m0
120 
121  .section .reset, "a", %progbits
122 
123  .align 2
124 
125  .globl __Vectors
126  .type __Vectors, %object
127 __Vectors:
128  .long __initial_sp /* Top of Stack */
129  .long Reset_Handler /* Reset Handler */
130 /*
131  * All entries below are redundant for M0, but are retained because they can
132  * in the future be directly ported to M0 Plus devices.
133  */
134  .long 0 /* Reserved */
135  .long HardFault_Handler /* Hard Fault Handler */
136  .long CLKVAL1_SSW /* Reserved */
137  .long CLKVAL2_SSW /* Reserved */
138  .long WAIT_ASCBSL_ENTRY_SSW /* Reserved */
139 #ifdef RETAIN_VECTOR_TABLE
140  .long 0 /* Reserved */
141  .long 0 /* Reserved */
142  .long 0 /* Reserved */
143  .long 0 /* Reserved */
144  .long SVC_Handler /* SVCall Handler */
145  .long 0 /* Reserved */
146  .long 0 /* Reserved */
147  .long PendSV_Handler /* PendSV Handler */
148  .long SysTick_Handler /* SysTick Handler */
149 
150  /* Interrupt Handlers for Service Requests (SR) from XMC1400 Peripherals */
151  .long IRQ0_Handler /* SCU.SR0, CAN0.SR0, CCU40.SR0, SCU.SR0 | CAN0.SR0 */
152  .long IRQ1_Handler /* SCU.SR1, CAN0.SR1, CCU80.SR0, SCU.SR1 | CAN0.SR1 */
153  .long IRQ2_Handler /* SCU.SR2, CAN0.SR2, CCU80.SR1, SCU.SR2 | CAN0.SR2 */
154  .long IRQ3_Handler /* ERU0.SR0, ERU1.SR0, CAN0.SR0, ERU0.SR0 | ERU1.SR0 */
155  .long IRQ4_Handler /* ERU0.SR1, ERU1.SR1, CAN0.SR1, ERU0.SR1 | ERU1.SR1 */
156  .long IRQ5_Handler /* ERU0.SR2, ERU1.SR2, CAN0.SR2, ERU0.SR2 | ERU1.SR2 */
157  .long IRQ6_Handler /* ERU0.SR3, ERU1.SR3, CAN0.SR3, ERU0.SR3 | ERU1.SR3 */
158  .long IRQ7_Handler /* MATH.SR0, CAN0.SR3, CCU40.SR1, MATH.SR0 | CAN0.SR3 */
159  .long IRQ8_Handler /* LEDTS2.SR0, CCU40.SR0, CCU80.SR0, LEDTS2.SR0 | CCU40.SR0 */
160  .long IRQ9_Handler /* USIC0.SR0, USIC1.SR0, ERU0.SR0, USIC0.SR0 | USIC1.SR0 */
161  .long IRQ10_Handler /* USIC0.SR1, USIC1.SR1, ERU0.SR1, USIC0.SR1 | USIC1.SR1 */
162  .long IRQ11_Handler /* USIC0.SR2, USIC1.SR2, ERU0.SR2, USIC0.SR2 | USIC1.SR2 */
163  .long IRQ12_Handler /* USIC0.SR3, USIC1.SR3, ERU0.SR3, USIC0.SR3 | USIC1.SR3 */
164  .long IRQ13_Handler /* USIC0.SR4, USIC1.SR4, CCU80.SR1, USIC0.SR4 | USIC1.SR4 */
165  .long IRQ14_Handler /* USIC0.SR5, USIC1.SR5, POSIF0.SR0, USIC0.SR5 | USIC1.SR5 */
166  .long IRQ15_Handler /* VADC0.C0SR0, USIC0.SR0, POSIF0.SR1, VADC0.C0SR0 | USIC0.SR0 */
167  .long IRQ16_Handler /* VADC0.C0SR1, USIC0.SR1, CCU40.SR2, VADC0.C0SR1 | USIC0.SR1 */
168  .long IRQ17_Handler /* VADC0.G0SR0, USIC0.SR2, CAN0.SR0, VADC0.G0SR0 | USIC0.SR2 */
169  .long IRQ18_Handler /* VADC0.G0SR1, USIC0.SR3, CAN0.SR1, VADC0.G0SR1 | USIC0.SR3 */
170  .long IRQ19_Handler /* VADC0.G1SR0, USIC0.SR4, CAN0.SR2, VADC0.G1SR0 | USIC0.SR4 */
171  .long IRQ20_Handler /* VADC0.G1SR1, USIC0.SR5, CAN0.SR3, VADC0.G1SR1 | USIC0.SR5 */
172  .long IRQ21_Handler /* CCU40.SR0, CCU41.SR0, USIC0.SR0, CCU40.SR0 | CCU41.SR0 */
173  .long IRQ22_Handler /* CCU40.SR1, CCU41.SR1, USIC0.SR1, CCU40.SR1 | CCU41.SR1 */
174  .long IRQ23_Handler /* CCU40.SR2, CCU41.SR2, USIC0.SR2, CCU40.SR2 | CCU41.SR2 */
175  .long IRQ24_Handler /* CCU40.SR3, CCU41.SR3, USIC0.SR3, CCU40.SR3 | CCU41.SR3 */
176  .long IRQ25_Handler /* CCU80.SR0, CCU81.SR0, USIC0.SR4, CCU80.SR0 | CCU81.SR0 */
177  .long IRQ26_Handler /* CCU80.SR1, CCU81.SR1, USIC0.SR5, CCU80.SR1 | CCU81.SR1 */
178  .long IRQ27_Handler /* POSIF0.SR0, POSIF1.SR0, CCU40.SR3, POSIF0.SR0 | POSIF1.SR0 */
179  .long IRQ28_Handler /* POSIF0.SR1, POSIF1.SR1, ERU0.SR0, POSIF0.SR1 | POSIF1.SR1 */
180  .long IRQ29_Handler /* LEDTS0.SR0, CCU40.SR1, ERU0.SR1, LEDTS0.SR0 | CCU40.SR1 */
181  .long IRQ30_Handler /* LEDTS1.SR0, CCU40.SR2, ERU0.SR2, LEDTS1.SR0 | CCU40.SR2 */
182  .long IRQ31_Handler /* BCCU0.SR0, CCU40.SR3, ERU0.SR3, BCCU0.SR0 | CCU40.SR3 */
183 #endif
184 
185  .size __Vectors, . - __Vectors
186 /* ================== END OF VECTOR TABLE DEFINITION ======================= */
187 
188 /* ================== START OF VECTOR ROUTINES ============================= */
189 
190  .thumb
191  .align 1
192 
193 /* Reset Handler */
194  .thumb_func
195  .globl Reset_Handler
196  .type Reset_Handler, %function
197 Reset_Handler:
198 /* Initialize interrupt veneer */
199  ldr r1, =eROData
200  ldr r2, =VeneerStart
201  ldr r3, =VeneerEnd
202  bl __copy_data
203 
204  ldr r0, =SystemInit
205  blx r0
206 
207 /* Initialize data */
208  ldr r1, =DataLoadAddr
209  ldr r2, =__data_start
210  ldr r3, =__data_end
211  bl __copy_data
212 
213 /* RAM code */
214  ldr r1, =__ram_code_load
215  ldr r2, =__ram_code_start
216  ldr r3, =__ram_code_end
217  bl __copy_data
218 
219 /* Define __SKIP_BSS_CLEAR to disable zeroing uninitialzed data in startup.
220  * The BSS section is specified by following symbols
221  * __bss_start__: start of the BSS section.
222  * __bss_end__: end of the BSS section.
223  *
224  * Both addresses must be aligned to 4 bytes boundary.
225  */
226 #ifndef __SKIP_BSS_CLEAR
227  ldr r1, =__bss_start
228  ldr r2, =__bss_end
229 
230  movs r0, 0
231 
232  subs r2, r1
233  ble .L_loop3_done
234 
235 .L_loop3:
236  subs r2, #4
237  str r0, [r1, r2]
238  bgt .L_loop3
239 .L_loop3_done:
240 #endif /* __SKIP_BSS_CLEAR */
241 
242 #ifndef __SKIP_LIBC_INIT_ARRAY
243  ldr r0, =__libc_init_array
244  blx r0
245 #endif
246 
247  ldr r0, =main
248  blx r0
249 
250  .thumb_func
251  .type __copy_data, %function
252 __copy_data:
253 /* The ranges of copy from/to are specified by following symbols
254  * r1: start of the section to copy from.
255  * r2: start of the section to copy to
256  * r3: end of the section to copy to
257  *
258  * All addresses must be aligned to 4 bytes boundary.
259  * Uses r0
260  */
261  subs r3, r2
262  ble .L_loop_done
263 
264 .L_loop:
265  subs r3, #4
266  ldr r0, [r1,r3]
267  str r0, [r2,r3]
268  bgt .L_loop
269 
270 .L_loop_done:
271  bx lr
272 
273  .pool
274  .size Reset_Handler,.-Reset_Handler
275 /* ======================================================================== */
276 /* ========== START OF EXCEPTION HANDLER DEFINITION ======================== */
277 
278  .align 1
279 
280  .thumb_func
281  .weak Default_handler
282  .type Default_handler, %function
283 Default_Handler:
284  b .
285  .size Default_Handler, . - Default_Handler
286 
287  Insert_InterruptHandler HardFault
288  Insert_InterruptHandler SVC
289  Insert_InterruptHandler PendSV
290  Insert_InterruptHandler SysTick
291 
292  Insert_InterruptHandler IRQ0
293  Insert_InterruptHandler IRQ1
294  Insert_InterruptHandler IRQ2
295  Insert_InterruptHandler IRQ3
296  Insert_InterruptHandler IRQ4
297  Insert_InterruptHandler IRQ5
298  Insert_InterruptHandler IRQ6
299  Insert_InterruptHandler IRQ7
300  Insert_InterruptHandler IRQ8
301  Insert_InterruptHandler IRQ9
302  Insert_InterruptHandler IRQ10
303  Insert_InterruptHandler IRQ11
304  Insert_InterruptHandler IRQ12
305  Insert_InterruptHandler IRQ13
306  Insert_InterruptHandler IRQ14
307  Insert_InterruptHandler IRQ15
308  Insert_InterruptHandler IRQ16
309  Insert_InterruptHandler IRQ17
310  Insert_InterruptHandler IRQ18
311  Insert_InterruptHandler IRQ19
312  Insert_InterruptHandler IRQ20
313  Insert_InterruptHandler IRQ21
314  Insert_InterruptHandler IRQ22
315  Insert_InterruptHandler IRQ23
316  Insert_InterruptHandler IRQ24
317  Insert_InterruptHandler IRQ25
318  Insert_InterruptHandler IRQ26
319  Insert_InterruptHandler IRQ27
320  Insert_InterruptHandler IRQ28
321  Insert_InterruptHandler IRQ29
322  Insert_InterruptHandler IRQ30
323  Insert_InterruptHandler IRQ31
324 
325 /* ======================================================================== */
326 
327 /* ==================VENEERS VENEERS VENEERS VENEERS VENEERS=============== */
328  .section ".XmcVeneerCode","ax",%progbits
329 
330  .align 1
331 
332  Insert_InterruptVeener HardFault
333  .long 0
334  .long 0
335  .long 0
336  .long 0
337  .long 0
338  .long 0
339  .long 0
340  Insert_InterruptVeener SVC
341  .long 0
342  .long 0
343  Insert_InterruptVeener PendSV
344  Insert_InterruptVeener SysTick
345 
346  Insert_InterruptVeener IRQ0
347  Insert_InterruptVeener IRQ1
348  Insert_InterruptVeener IRQ2
349  Insert_InterruptVeener IRQ3
350  Insert_InterruptVeener IRQ4
351  Insert_InterruptVeener IRQ5
352  Insert_InterruptVeener IRQ6
353  Insert_InterruptVeener IRQ7
354  Insert_InterruptVeener IRQ8
355  Insert_InterruptVeener IRQ9
356  Insert_InterruptVeener IRQ10
357  Insert_InterruptVeener IRQ11
358  Insert_InterruptVeener IRQ12
359  Insert_InterruptVeener IRQ13
360  Insert_InterruptVeener IRQ14
361  Insert_InterruptVeener IRQ15
362  Insert_InterruptVeener IRQ16
363  Insert_InterruptVeener IRQ17
364  Insert_InterruptVeener IRQ18
365  Insert_InterruptVeener IRQ19
366  Insert_InterruptVeener IRQ20
367  Insert_InterruptVeener IRQ21
368  Insert_InterruptVeener IRQ22
369  Insert_InterruptVeener IRQ23
370  Insert_InterruptVeener IRQ24
371  Insert_InterruptVeener IRQ25
372  Insert_InterruptVeener IRQ26
373  Insert_InterruptVeener IRQ27
374  Insert_InterruptVeener IRQ28
375  Insert_InterruptVeener IRQ29
376  Insert_InterruptVeener IRQ30
377  Insert_InterruptVeener IRQ31
378 
379 /* ======================================================================== */
380 /* ======================================================================== */
381 
382 /* ============= END OF INTERRUPT HANDLER DEFINITION ======================== */
383 
384  .end